package com.mk.cloud.common.enums;

import act.Act;
import com.mk.cloud.common.domain.CpConfig;
import org.osgl.util.S;

public enum ConfigCode {
    /**
     * 奖励说明:
     * 第一种:购买新店体验奖励
     * A为合伙人,A介绍B,B介绍C
     * 场景1:B介绍C, 则B得到INTRODUCTION_REWARD2的奖励,A得到INTRODUCTION_REWARD1的奖励
     * 场景2:A介绍B, 则A得到INTRODUCTION_REWARD的奖励
     *git chegit
     * 爆品购买奖励
     * 场景:合伙人A分享给B,则A得到INTRODUCTION_REWARD_BP奖励
     *
     */

    FIRST_ORDER_REWARD("现场签单产品返利（%）", "^(?:0|[1-9][0-9]?|100)$", "20", "0~100的整数,代表现场签单总额多少百分比的产品返利,0表示无奖励."),
    INTRODUCTION_REWARD_BP("爆品体验现金奖励(元)","^(?:0|[1-9][0-9]?|100)$","500","合伙人每成功介绍一家购买爆品的新店,即可获得现金奖励,默认为500元"),
    INTRODUCTION_REWARD("新店体验现金奖励(%)","^(?:0|[1-9][0-9]?|100)$","20","合伙人每成功介绍一家,即可获得新店签订方案百分比的现金奖励,默认为20%"),
    INTRODUCTION_REWARD1("新店体验现金奖励合伙人下级得(%)","^(?:0|[1-9][0-9]?|100)$","0","合伙人的下级转介绍的店铺转介绍成功一家,即可获得新店签订方案百分比的现金奖励,默认为0%"),
    INTRODUCTION_REWARD2("新店体验现金奖励合伙人下下级得(%)","^(?:0|[1-9][0-9]?|100)$","0","合伙人的下下级转介绍成功一家,即可获得新店签订方案百分比的现金奖励,默认为0%"),
    FISSION_10_REWARD("小组裂变10家奖励(元)","^[1-9]{1}\\d{0,8}$|^0$","0","一年内小组裂变店家达到10家即可获得盘价奖励"),

    FISSION_PK_REWARD("裂变PK奖励(元)","","[[\"1\",\"300\"],[\"2\",\"400\"],[\"3\",\"500\"]]","每半年结算一次,根据比例得现金奖励"),

    SERVICE_CHARGE("提现手续费(元)","^[1-9]{1}\\d{0,8}$|^0$","0","每次提现收取的手续费,默认为0"),

    ;
//    MAX_RECHARGE_MONTH("测试配置（元）", "^[1-9]{1}\\d{0,8}$|^0$", "0", "0表示不限制,必须输入整数");

    private final String label;
    private final String part;
    private final String def_value;
    private final String desc;

    ConfigCode(String label, String part, String def_value, String desc) {
        this.label = label;
        this.part = part;
        this.def_value = def_value;
        this.desc = desc;
    }


    public CpConfig convertConfig(String coid){
        CpConfig config = new CpConfig();
        config.setCfid(name());
        if(S.isNotBlank(coid)){
            config.setCoid(coid);
        }else{
            config.setCoid("");
        }
        CpConfig c = Act.getInstance(CpConfig.Mapper.class).single(config);
        CpConfig result = new CpConfig();
        result.setLabel(label);
        result.setValue(c != null ? c.getCfvalue() : def_value);
        result.setName(name());
        result.setPart(part);
        result.setDesc(desc);
        return result;
    }

    public String value(String coid){
//        CpConfig c = Act.getInstance(CpConfig.Mapper.class).single(name());
        CpConfig config = new CpConfig();
        config.setCfid(name());
        if(S.isNotBlank(coid)){
            config.setCoid(coid);
        }else{
            config.setCoid("");
        }
        CpConfig c = Act.getInstance(CpConfig.Mapper.class).single(config);
        return c != null ? c.getCfvalue() : def_value;
    }


}